﻿Imports BUS, DTO
Public Class frmcapnhatthedocgia

    Private _docgia As New DocGiaDTO()
    Public Property docgia() As DocGiaDTO
        Get
            Return _docgia
        End Get
        Set(ByVal value As DocGiaDTO)
            _docgia = value
        End Set
    End Property

    Private Sub SimpleButton_CapNhat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SimpleButton_CapNhat.Click

        Dim _rowsIndex As Integer = DataGridView_DanhSachDocGia.CurrentRow.Index
        docgia.MaDocGia = DataGridView_DanhSachDocGia.Rows(_rowsIndex).Cells(0).Value.ToString()
        docgia.TenDocGia = DataGridView_DanhSachDocGia.Rows(_rowsIndex).Cells(1).Value.ToString()
        docgia.MaLoaiDocGia = DataGridView_DanhSachDocGia.Rows(_rowsIndex).Cells(2).Value.ToString()
        docgia.NgaySinh = DataGridView_DanhSachDocGia.Rows(_rowsIndex).Cells(3).Value.ToString()
        docgia.DiaChi = DataGridView_DanhSachDocGia.Rows(_rowsIndex).Cells(4).Value.ToString()
        docgia.Email = DataGridView_DanhSachDocGia.Rows(_rowsIndex).Cells(5).Value.ToString()
        docgia.NgayLapThe = DataGridView_DanhSachDocGia.Rows(_rowsIndex).Cells(6).Value.ToString()
        docgia.MaNhanVien = DataGridView_DanhSachDocGia.Rows(_rowsIndex).Cells(7).Value.ToString()
        Dim fr As New frmxlcapnhatthedocgia()
        fr.MaDocGia = docgia.MaDocGia
        fr.txthoten.Text = docgia.TenDocGia
        fr.txtdiachi.Text = docgia.DiaChi
        fr.txtemail.Text = docgia.Email
        fr.DateEditngaysinh.DateTime = docgia.NgaySinh
        fr.DateEditngaylapthe.DateTime = docgia.NgayLapThe

        Dim ldgBUS As New LoaiDocGiaBUS()
        Dim dsldg As New List(Of LoaiDocGiaDTO)
        dsldg = ldgBUS.LayDSLoaiDocGia()
        fr.LookUpEdit_LoaiDocGia.Properties.DataSource = dsldg
        fr.LookUpEdit_LoaiDocGia.Properties.ValueMember = "MaLoaiDocGia"
        fr.LookUpEdit_LoaiDocGia.Properties.DisplayMember = "MaLoaiDocGia"


        Dim nhanvienBUS As New NhanVienBUS()
        Dim dsnhanvien As New List(Of NhanVienDTO)
        dsnhanvien = nhanvienBUS.LayDSNhanVien_ThuThu()
        fr.LookUpnguoilap.Properties.DataSource = dsnhanvien
        fr.LookUpnguoilap.Properties.ValueMember = "MaNhanVien"
        fr.LookUpnguoilap.Properties.DisplayMember = "HoTen"

        fr.LookUpEdit_LoaiDocGia.EditValue = docgia.MaLoaiDocGia
        fr.LookUpnguoilap.EditValue = docgia.MaNhanVien

        fr.ShowDialog()
    End Sub

    Private Sub LoadDSDocGia()
        DataGridView_DanhSachDocGia.Rows.Clear()
        Dim bus As New DocGiaBUS()
        Dim dsDocGia As New List(Of DocGiaDTO)
        dsDocGia = bus.LayDSDocGia()

        For index As Integer = 0 To dsDocGia.Count - 1
            DataGridView_DanhSachDocGia.Rows.Add(dsDocGia(index).MaDocGia, dsDocGia(index).TenDocGia, dsDocGia(index).MaLoaiDocGia, dsDocGia(index).NgaySinh, dsDocGia(index).DiaChi, dsDocGia(index).Email, dsDocGia(index).NgayLapThe, dsDocGia(index).MaNhanVien)
        Next
    End Sub

    Private Sub frmcapnhatthedocgia_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LoadDSDocGia()

    End Sub
End Class